package mao.exaimnation.huawei.practice;

import java.util.Scanner;

/**
 * @author Totoro
 * @date 2020/8/12
 * @explain:
 */
public class Main {


     static class Main_{
        public static  void main(String[] args){
            Scanner sc = new Scanner(System.in);
            while(sc.hasNextLine()){
                int n = sc.nextInt();
                int m = sc.nextInt();
                int[] grades = new int[n];
                for(int i=0;i<n;i++){
                    grades[i] = sc.nextInt();
                }
                sc.nextLine();
                for(int i=0;i<m;i++){
                    String str = sc.nextLine();
                    String[] strSplit = str.split(" ");
                    int a = Integer.parseInt(strSplit[1]);
                    int b = Integer.parseInt(strSplit[2]);
                    int max = 0;
                    switch(str.charAt(0)){
                        case 'Q':
                            max = 0;
                            if (a>b){
                                int tmp = a;
                                a = b;
                                b = tmp;
                            }
                            for(int j=a;j<=b;j++){
                                max=Math.max(max,grades[j-1]);
                            }
                            System.out.println(max);
                            break;
                        case 'U':
                            grades[a-1] = b;
                            break;
                        default:
                            break;
                    }
                }
            }
        }
    }
}
